/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package au.edu.swin.swinvehicle.vehiclebooking;

import au.edu.swin.swinvehicle.bookingtype.BookingTypeEntity;
import au.edu.swin.swinvehicle.corporateclient.CorporateClientEntity;
import au.edu.swin.swinvehicle.driver.DriverEntity;
import au.edu.swin.swinvehicle.eventtype.EventTypeEntity;
import au.edu.swin.swinvehicle.vehicle.VehicleEntity;
import au.edu.swin.swinvehicle.vehicletype.VehicleTypeEntity;
import java.io.Serializable;
import java.sql.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 *
 * @author Administrator
 */
@Entity
@NamedQueries({
    @NamedQuery(name = "findAllVehicleBookings",
    query = "SELECT vb FROM VehicleBookingEntity vb WHERE vb.deleted = false"),
    @NamedQuery(name = "findVehicleBookingsByFilter",
    query = "SELECT vb FROM VehicleBookingEntity vb WHERE vb.deleted = false " +
            "AND (:driverIsNull = true OR vb.driver.id = :driverId) " +
            "AND (:vehicleIsNull = true OR vb.vehicle.id = :vehicleId) " +
            "AND (:corporateClientIsNull = true OR vb.corporateClient.id = :corporateClientId)")
})
@Table(name = "VEHICLEBOOKING")
public class VehicleBookingEntity implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    @Column(length = 63, nullable = false)
    private String contactName;
    @Column(length = 20, nullable = false)
    private String contactPhone;
    @Column(length = 63)
    private String contactEmail;
    @Column(length = 63, nullable = false)
    private String customerName;
    @Column(nullable = false)
    private Date pickUpDate;
    @Column(length = 255, nullable = false)
    private String pickUpAddress;
    @Column(length = 255, nullable = false)
    private String dropOffAddress;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private BookingTypeEntity bookingType;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private EventTypeEntity eventType;
    @ManyToOne(optional = false, cascade = CascadeType.PERSIST)
    private VehicleTypeEntity vehicleType;
    @Column(length = 63, nullable = false)
    private String specialRequirement;
    @Column(length = 255, nullable = false)
    private String comment;
    @ManyToOne(optional = true, cascade = CascadeType.PERSIST)
    private CorporateClientEntity corporateClient;
    @ManyToOne(optional = true, cascade = CascadeType.PERSIST)
    private VehicleEntity vehicle;
    @ManyToOne(optional = true, cascade = CascadeType.PERSIST)
    private DriverEntity driver;
    @Column(nullable = false)
    private boolean completed;
    @Column(nullable = false)
    private boolean deleted;

    /**
     * Default constructor
     */
    public VehicleBookingEntity() {
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getContactName() {
        return contactName;
    }

    public void setContactName(String contactName) {
        this.contactName = contactName;
    }

    public String getContactPhone() {
        return contactPhone;
    }

    public void setContactPhone(String contactPhone) {
        this.contactPhone = contactPhone;
    }

    public String getContactEmail() {
        return contactEmail;
    }

    public void setContactEmail(String contactEmail) {
        this.contactEmail = contactEmail;
    }

    public String getCustomerName() {
        return customerName;
    }

    public void setCustomerName(String customerName) {
        this.customerName = customerName;
    }

    public Date getPickUpDate() {
        return pickUpDate;
    }

    public void setPickUpDate(Date pickUpDate) {
        this.pickUpDate = pickUpDate;
    }

    public String getPickUpAddress() {
        return pickUpAddress;
    }

    public void setPickUpAddress(String pickUpAddress) {
        this.pickUpAddress = pickUpAddress;
    }

    public String getDropOffAddress() {
        return dropOffAddress;
    }

    public void setDropOffAddress(String dropOffAddress) {
        this.dropOffAddress = dropOffAddress;
    }

    public BookingTypeEntity getBookingType() {
        return bookingType;
    }

    public void setBookingType(BookingTypeEntity bookingType) {
        this.bookingType = bookingType;
    }

    public EventTypeEntity getEventType() {
        return eventType;
    }

    public void setEventType(EventTypeEntity eventType) {
        this.eventType = eventType;
    }

    public VehicleTypeEntity getVehicleType() {
        return vehicleType;
    }

    public void setVehicleType(VehicleTypeEntity vehicleType) {
        this.vehicleType = vehicleType;
    }

    public String getSpecialRequirement() {
        return specialRequirement;
    }

    public void setSpecialRequirement(String specialRequirement) {
        this.specialRequirement = specialRequirement;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public CorporateClientEntity getCorporateClient() {
        return corporateClient;
    }

    public void setCorporateClient(CorporateClientEntity corporateClient) {
        this.corporateClient = corporateClient;
    }

    public DriverEntity getDriver() {
        return driver;
    }

    public void setDriver(DriverEntity driver) {
        this.driver = driver;
    }

    public VehicleEntity getVehicle() {
        return vehicle;
    }

    public void setVehicle(VehicleEntity vehicle) {
        this.vehicle = vehicle;
    }

    public boolean isCompleted() {
        return completed;
    }

    public void setCompleted(boolean completed) {
        this.completed = completed;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    // Transfer Object Methods
    public VehicleBookingDetailedTO getDetailedData() {
        return new VehicleBookingDetailedTO(id, contactName, contactPhone, contactEmail, customerName, new java.util.Date(pickUpDate.getTime()), pickUpAddress, dropOffAddress, bookingType.getData(), eventType.getData(), vehicleType.getData(), specialRequirement, comment, (corporateClient != null) ? corporateClient.getData() : null, (vehicle != null) ? vehicle.getData() : null, (driver != null) ? driver.getData() : null, completed);
    }

    public void setData(VehicleBookingDetailedTO to) {
        this.setId(to.getId());
        this.setContactName(to.getContactName());
        this.setContactPhone(to.getContactPhone());
        this.setContactEmail(to.getContactEmail());
        this.setCustomerName(to.getCustomerName());
        this.setPickUpDate(new Date(to.getPickUpDate().getTime()));
        this.setPickUpAddress(to.getPickUpAddress());
        this.setDropOffAddress(to.getDropOffAddress());
        this.setSpecialRequirement(to.getSpecialRequirement());
        this.setComment(to.getComment());
    }

    @Override
    public String toString() {
        return "au.edu.swin.swinvehicle.vehiclebooking.VehicleBookingEntity[id=" + id + "]";
    }
}
